class Dialog {

    static newIconNameDialog(layer) {

        let layerName = layer.name();

        if(layerName.indexOf('+')!=-1) {
            layerName = layerName.slice(layerName.indexOf(separator)+1);
        } else {
            layerName = layerName.split('/').pop();
        }

        //创建窗口
        let alert = Dialog.createBasicDialog(true, "确定")
        alert.setMessageText("图标命名");

        //图标的名字
        alert.addTextLabelWithValue('图标名字: ');
        let nameField = Dialog.createTextField(layerName);
        alert.addAccessoryView(nameField);

        //分隔线
        alert.addAccessoryView(Dialog.createSeparator());

        //描述图标的形容词
        alert.addTextLabelWithValue('请选择两到三个形容词修饰图标');

        //大小
        let sizes = ["大小", "Mini", "Small", "Normal", "Big", "Large", "Huge"];
        let sizeSelection = Dialog.createDropdown(sizes);
        alert.addAccessoryView(sizeSelection);

        //颜色
        let colorView = NSView.alloc().initWithFrame(NSMakeRect(0,0,300,28));

        let colors = ["颜色", "Gray", "White", "Blue", "Black", "Red", "Green"];
        let colorSelection = Dialog.createDropdown(colors);
        colorView.addSubview(colorSelection);

        //let stringLabel = NSTextView.alloc().initWithFrame(NSMakeRect(137, 0, 20, 22));
        //stringLabel.insertText("或");

        // stringLabel.backgroundColor(UIColor.redColor);
        //colorView.addSubview(stringLabel);

        //let colorField = NSTextField.alloc().initWithFrame(NSMakeRect(157, 4, 120, 22));
        //colorField.placeholderString = "自定义颜色值";
        //colorField.setEditable(true);
        //colorField.setSelectable(true);

        //colorView.addSubview(colorField);

        alert.addAccessoryView(colorView);


        //是否镂空
        let fills = ["是否镂空", "Fill", "Ghost"];
        let fillSelection = Dialog.createDropdown(fills);
        alert.addAccessoryView(fillSelection);

        //展示窗口
        let responseCode = alert.runModal();
        // let guide = layers[layerSelection.indexOfSelectedItem()]; //Layer selected by user.

        //Return Values
        let inputs = {
            responseCode: responseCode,
            size: sizeSelection.objectValueOfSelectedItem(),
            color: colorSelection.objectValueOfSelectedItem(),
            fill: fillSelection.objectValueOfSelectedItem(),
            name: nameField.stringValue()
        }
        return inputs;
    }

    // UI Creators
    static newInformationDialog(title, message) {
        let dialog = Dialog.createBasicDialog(false)
        dialog.setMessageText(title);
        dialog.setInformativeText(message);

        return dialog.runModal();
    }

    // UI
    static createBasicDialog(showsCancel, acceptText) {
        let alert = COSAlertWindow.new();

        //let iconURL = plugin.urlForResourceNamed("icon.icns").path()
        //let icon = NSImage.alloc().initByReferencingFile(iconURL);
        //alert.setIcon(icon);

        alert.addButtonWithTitle(acceptText ? acceptText : '确认');
        if (showsCancel) alert.addButtonWithTitle('取消');
        return alert
    }

    static createTextField(placeholder) {
        var textbox = NSTextField.alloc().initWithFrame(NSMakeRect(0, 0, 180, 22));
        textbox.placeholderString = placeholder;
        textbox.setEditable(true);
        textbox.setSelectable(true);
        return textbox
    }

    static createDropdown(items) {
        let dropdown = NSComboBox.alloc().initWithFrame(NSMakeRect(0, 0, 180, 28));
        dropdown.addItemsWithObjectValues(items);
        dropdown.setEditable(false);
        dropdown.selectItemAtIndex(0)
        return dropdown;
    }

    static createSeparator() {
        let separator = NSBox.alloc().initWithFrame(NSMakeRect(0, 0, 250, 10));
        separator.setBoxType(2);
        return separator
    }

}